<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .container-wrapper {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 15px;
            margin-top: 10px;

            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 15px;
            padding: 16px;

        }

        .container {
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            align-items: center;
            text-align: center;
            width: 40%;
            height: 90px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 15px;
            padding: 16px;
            cursor: pointer;
            transition: transform 0.2s;
        }

        .container img {
            max-height: 30px;
            margin-bottom: 8px;
        }

        .task-text {
            font-size: 15px;
            font-weight: bold;
            color: rgb(255, 255, 255);
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            任务单创建/执行
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">

        <ul class='aui-list aui-media-list ui-selectee' style="position: static;">
            <li class='aui-list-item  ui-selectee' style='color: black !important;background-color: transparent'>
                <div class='aui-list-item-inner ui-selectee '>
                    <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                        <div class='aui-list-item-label ui-selectee list-tr-title' style="font-size: 16px;font-weight: 600;">
                            机台号:</div>
                        <div class="aui-list-item-input">
                            <input type="text" id="equipmentno" disabled="true" />
                        </div>
                    </div>
                    <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                        <div class='aui-list-item-label ui-selectee list-tr-title' style="font-size: 16px;font-weight: 600;">
                            机台名称:</div>
                        <div class="aui-list-item-input">
                            <input type="text" id="equipmentname" disabled="true" />
                        </div>
                    </div>
                    <div class='aui-list-item-text ui-selectee' style='height: 30px;'>
                        <div class='aui-list-item-label ui-selectee list-tr-title' style="font-size: 16px;font-weight: 600;">日期:
                        </div>
                        <div class="aui-list-item-input" onclick="timePicker();">
                            <input type="text" placeholder="选择日期" id="datetime" class="aui-input" />
                        </div>
                    </div>
                </div>
                </div>
            </li>
        </ul>

    <div class="container-wrapper">
        <div class="container" style="background-color: #2ea294;" onclick="addTaskBefor();">
            <img src="../image/add.png" alt="新增任务图标">
            <div class="task-text">新增任务</div>
        </div>
        <div class="container" style="background-color: #03a9f4;" onclick="goPageSelect()">
            <img src="../image/select2.0.png" alt="查询任务图标">
            <div class="task-text">查询任务</div>
        </div>
    </div>
    <ul class="ui-selectee" id="tbodyHtml">

    </ul>
    </div>
    <div style="height:60px;"></div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jdate.min.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var equipmentno = ""; //机台号
    var type = ""; //设备维保类型
    var equipmentname = ""; //机台名称


    //初始化查询
    apiready = function () {
        type = api.pageParam.type; //设备维保类型
        equipmentno = api.pageParam.equipmentno;
        equipmentname = api.pageParam.equipmentname;
        $("#equipmentno").val(equipmentno);
        $("#equipmentname").val(equipmentname);

        //今天的时间
        var dayS = new Date();
        dayS.setTime(dayS.getTime());
        var mm = (dayS.getMonth() + 1) >= 10 ? (dayS.getMonth() + 1) : "0" + (dayS.getMonth() + 1);
        var dd = dayS.getDate() >= 10 ? dayS.getDate() : "0" + dayS.getDate();
        var start =
            dayS.getFullYear() + "-" + mm + "-" + dd;

        $("#datetime").val(start);

        //  查询
        search()

    }

    function addTaskBefor() {
        var datetime = $("#datetime").val();
        api.confirm({
            title: '系统提示：',
            msg: '是否确认生成任务单\n机台【' + equipmentno + '】\n计划日期【' + datetime + '】',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            if (ret.buttonIndex == 1) {
                addTask()
            }
        });
    }

    //保存按钮
    function addTask() {
        var datetime = $("#datetime").val();

        api.showProgress({
            title: '创建中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/addTaskSave";
        var data = {
            values: {
                un: un,
                datetime: datetime,
                equipmentno: equipmentno,
                type: type,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    api.hideProgress();
                    api.toast({
                        msg: "创建成功",
                        duration: 3000
                    });
                    search()
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
            }
        });
    }

    //时间选择器
    function timePicker(id) {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#datetime").val(date);
                 //  查询
        search()
            }
        });
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }
    //跳转详情页面
    function goPageSelect() {
        var datetime = $("#datetime").val();
        //打开页面
        api.openWin({
            name: 'selectEquipTaskAll',
            url: 'selectEquipTaskAll' + '.html',
            pageParam: {
                datetime: datetime,
                equipmentno: equipmentno,
                type: type,
            },
        });
    }

    function search() {
        var datetime = $("#datetime").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/searchEquipTaskList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                equipCode: equipmentno,
                datetime: datetime,
                type: type,
                selectSin: 'Y',//查询待处理，处理中
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    list = myobj.list;
                    setTable(list)
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });

                }
            }
        });
    }


    function setTable(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {
            html += "<div style='padding-top:4%;'></div>";
            html += "<li class='sortable ui-selectee ui-sortable' >";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";
            html += "<li class='aui-list-item  ui-selectee' style='color: black !important;background-color: #addbef !important;'>";
            html += "<div class='aui-media-list-item-inner ui-selectee ' >";
            html += "<div class='aui-list-item-inner ui-selectee '>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>任务号:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].task_code + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>创建时间:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].create_date + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 25px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title' style='width:65%'>单据状态:</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].taskStateName + "</div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee' style='background-color:#FA8072' onclick='deleteTab(\"" + list[i].task_code + "\");'>删除</div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee' onclick='deal(\"" + list[i].task_code + "\");'>处理</div>";
            html += "</div>";

            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        $api.html($api.byId("tbodyHtml"), html);
    };

    //处理
    function deal(taskCode) {

        api.openWin({
            name: 'equipTaskDeal',
            url: 'equipTaskDeal.html',
            pageParam: {
                taskCode: taskCode,
                equipmentno: equipmentno,
                equipmentname: equipmentname,
                type: type,
                name: "selectEquipTaskInfo",
            }
        });
    }



    //删除
    function deleteTab(taskCode) {
        api.confirm({
            title: '系统提示：',
            msg: '是否确认删除任务单【' + taskCode + '】',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            if (ret.buttonIndex == 1) {
                api.showProgress({
                    title: '删除中...',
                });
                var un = localStorage.getItem('un');
                var serverUrl = localStorage.getItem('serverUrl');
                var url = serverUrl + "/app/deleteTaskCodeCreate";
                var data = {
                    values: {
                        taskCode: taskCode,
                        un: un,
                    }
                };
                api.ajax({
                    url: url,
                    method: 'post',
                    dataType: 'json',
                    timeout: 300,
                    returnAll: false,
                    data: data
                }, function (ret, err) {
                    if (ret) {
                        var data = JSON.stringify(ret);
                        var map = eval("(" + data + ")");
                        if (map.code == "0") {
                            api.hideProgress();
                            api.toast({
                                msg: "删除成功",
                                duration: 3000
                            });
                            search()
                        } else {
                            api.hideProgress();
                            api.toast({
                                msg: map.message,
                                duration: 6000
                            });
                        }

                    } else {
                        api.hideProgress();
                    }
                });
            }
        });

    }
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }

</script>


</html>